
/**
 * Write a description of class SimpleTower here.
 * 
 * @author Karl Sturm
 * @version (a version number or a date)
 */

import java.awt.*;
import java.awt.event.*;
import java.util.*;

public class FreezeTower extends TOWER
{
    private double factor;
    public FreezeTower(int x_p, int y_p)
    {
        super(x_p,y_p);
        size = 20;
        radius = 80;
        damage = 0;
        factor = 1.2;
        isselected = false;
        drawRange = true;
        upgradelevel = 1;
        cost = 30;
        upgradecost = 6;
    }
    
    public void paint(Graphics g)
    {
        g.drawRect(x,y,size,size);
        g.setColor(java.awt.Color.cyan);
        g.fillRect(x+1,y+1,size-1,size-1);
        g.setColor(java.awt.Color.black);
        for(int i = 1; i <= upgradelevel; i++)
        {
            if(template == false)
            {
                g.drawRect(x-4+i*4, y, 4, 4);
            }
        }
        if(isselected == true)
        {
            g.setColor(Color.green);
            g.drawRect(x-1, y-1, size+2, size+2);
            g.drawRect(x-2, y-2, size+4, size+4);
            g.setColor(Color.black);
        }
        if((isselected == true) && (drawRange == true))
        {
            g.drawOval(x+size/2-radius,y+size/2-radius,radius*2,radius*2);
        }
    }
    public void work(ArrayList<CREEP> creeps)
    {
        count++;
        if(!creeps.isEmpty())
        {
            for(CREEP c : creeps)
            {
                if (c.freezeable())
                {
                    if( (int)Math.sqrt(Math.pow(c.getxPos()-x+size/2,2)+Math.pow(c.getyPos()-y+size/2,2)) > radius && c.getfrozen())
                    {
                        c.unfreeze();
                    }
                    else if( (int)Math.sqrt(Math.pow(c.getxPos()-x+size/2,2)+Math.pow(c.getyPos()-y+size/2,2)) <= radius && !c.getfrozen() )
                    {
                        c.freeze(factor);
                    }
                }
            }
        }
    }
    public int sell()
    {
        return (cost+upgradelevel*upgradecost-upgradecost)/2;
    }
    public void upgrade()
    {
        switch(upgradelevel)
        {
            case 1: 
            radius=83;
            factor=1.4;
            upgradelevel++;
            break;
            
            case 2:
            radius=85;
            factor=1.6;
            upgradelevel++;
            break;
            
            case 3:
            radius=87;
            factor=1.8;
            upgradelevel++;
            break;
        }
    }
}